home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_qt.idb / usr / freeware / include / Qt / qrect.h.z / qrect.h
Encoding:
C/C++ Source or Header  |  1998-10-28  |  5.0 KB  |  201 lines

  1. /****************************************************************************
  2. ** $Id: qrect.h,v 2.7 1998/07/03 00:09:40 hanord Exp $
  3. **
  4. ** Definition of QRect class
  5. **
  6. ** Created : 931028
  7. **
  8. ** Copyright (C) 1992-1998 Troll Tech AS.  All rights reserved.
  9. **
  10. ** This file is part of Qt Free Edition, version 1.40.
  11. **
  12. ** See the file LICENSE included in the distribution for the usage
  13. ** and distribution terms, or http://www.troll.no/free-license.html.
  14. **
  15. ** IMPORTANT NOTE: You may NOT copy this file or any part of it into
  16. ** your own programs or libraries.
  17. **
  18. ** Please see http://www.troll.no/pricing.html for information about 
  19. ** Qt Professional Edition, which is this same library but with a
  20. ** license which allows creation of commercial/proprietary software.
  21. **
  22. *****************************************************************************/
  23.  
  24. #ifndef QRECT_H
  25. #define QRECT_H
  26.  
  27. #ifndef QT_H
  28. #include "qsize.h"
  29. #endif // QT_H
  30.  
  31.  
  32. class QRect                    // rectangle class
  33. {
  34. public:
  35.     QRect()    { x1 = y1 = 0; x2 = y2 = -1; }
  36.     QRect( const QPoint &topleft, const QPoint &bottomright );
  37.     QRect( const QPoint &topleft, const QSize &size );
  38.     QRect( int left, int top, int width, int height );
  39.  
  40.     bool   isNull()    const;
  41.     bool   isEmpty()    const;
  42.     bool   isValid()    const;
  43.     QRect  normalize()    const;
  44.  
  45.     int       left()    const;
  46.     int       top()    const;
  47.     int       right()    const;
  48.     int       bottom()    const;
  49.     int       x()        const;
  50.     int       y()        const;
  51.     void   setLeft( int pos );
  52.     void   setTop( int pos );
  53.     void   setRight( int pos );
  54.     void   setBottom( int pos );
  55.     void   setX( int x );
  56.     void   setY( int y );
  57.  
  58.     QPoint topLeft()     const;
  59.     QPoint bottomRight() const;
  60.     QPoint topRight()     const;
  61.     QPoint bottomLeft()     const;
  62.     QPoint center()     const;
  63.  
  64.     void   rect( int *x, int *y, int *w, int *h ) const;
  65.     void   coords( int *x1, int *y1, int *x2, int *y2 ) const;
  66.  
  67.     void   moveTopLeft( const QPoint &p );
  68.     void   moveBottomRight( const QPoint &p );
  69.     void   moveTopRight( const QPoint &p );
  70.     void   moveBottomLeft( const QPoint &p );
  71.     void   moveCenter( const QPoint &p );
  72.     void   moveBy( int dx, int dy );
  73.  
  74.     void   setRect( int x, int y, int w, int h );
  75.     void   setCoords( int x1, int y1, int x2, int y2 );
  76.  
  77.     QSize  size()    const;
  78.     int       width()    const;
  79.     int       height()    const;
  80.     void   setWidth( int w );
  81.     void   setHeight( int h );
  82.     void   setSize( const QSize &s );
  83.  
  84.     bool   contains( const QPoint &p, bool proper=FALSE ) const;
  85.     bool   contains( const QRect &r, bool proper=FALSE ) const;
  86.     QRect  unite( const QRect &r ) const;
  87.     QRect  intersect( const QRect &r ) const;
  88.     bool   intersects( const QRect &r ) const;
  89.  
  90.     friend bool operator==( const QRect &, const QRect & );
  91.     friend bool operator!=( const QRect &, const QRect & );
  92.  
  93. private:
  94. #if defined(_OS_MAC_)
  95.     QCOORD y1;
  96.     QCOORD x1;
  97.     QCOORD y2;
  98.     QCOORD x2;
  99. #else
  100.     QCOORD x1;
  101.     QCOORD y1;
  102.     QCOORD x2;
  103.     QCOORD y2;
  104. #endif
  105. };
  106.  
  107. bool operator==( const QRect &, const QRect & );
  108. bool operator!=( const QRect &, const QRect & );
  109.  
  110. /*****************************************************************************
  111.   QRect stream functions
  112.  *****************************************************************************/
  113.  
  114. QDataStream &operator<<( QDataStream &, const QRect & );
  115. QDataStream &operator>>( QDataStream &, QRect & );
  116.  
  117.  
  118. /*****************************************************************************
  119.   QRect inline member functions
  120.  *****************************************************************************/
  121.  
  122. inline QRect::QRect( int left, int top, int width, int height )
  123. {
  124.     x1 = (QCOORD)left;
  125.     y1 = (QCOORD)top;
  126.     x2 = (QCOORD)(left+width-1);
  127.     y2 = (QCOORD)(top+height-1);
  128. }
  129.  
  130. inline bool QRect::isNull() const
  131. { return x2 == x1-1 && y2 == y1-1; }
  132.  
  133. inline bool QRect::isEmpty() const
  134. { return x1 > x2 || y1 > y2; }
  135.  
  136. inline bool QRect::isValid() const
  137. { return x1 <= x2 && y1 <= y2; }
  138.  
  139. inline int QRect::left() const
  140. { return x1; }
  141.  
  142. inline int QRect::top() const
  143. { return y1; }
  144.  
  145. inline int QRect::right() const
  146. { return x2; }
  147.  
  148. inline int QRect::bottom() const
  149. { return y2; }
  150.  
  151. inline int QRect::x() const
  152. { return x1; }
  153.  
  154. inline int QRect::y() const
  155. { return y1; }
  156.  
  157. inline void QRect::setLeft( int pos )
  158. { x1 = (QCOORD)pos; }
  159.  
  160. inline void QRect::setTop( int pos )
  161. { y1 = (QCOORD)pos; }
  162.  
  163. inline void QRect::setRight( int pos )
  164. { x2 = (QCOORD)pos; }
  165.  
  166. inline void QRect::setBottom( int pos )
  167. { y2 = (QCOORD)pos; }
  168.  
  169. inline void QRect::setX( int x )
  170. { x1 = (QCOORD)x; }
  171.  
  172. inline void QRect::setY( int y )
  173. { y1 = (QCOORD)y; }
  174.  
  175. inline QPoint QRect::topLeft() const
  176. { return QPoint(x1, y1); }
  177.  
  178. inline QPoint QRect::bottomRight() const
  179. { return QPoint(x2, y2); }
  180.  
  181. inline QPoint QRect::topRight() const
  182. { return QPoint(x2, y1); }
  183.  
  184. inline QPoint QRect::bottomLeft() const
  185. { return QPoint(x1, y2); }
  186.  
  187. inline QPoint QRect::center() const
  188. { return QPoint((x1+x2)/2, (y1+y2)/2); }
  189.  
  190. inline int QRect::width() const
  191. { return  x2 - x1 + 1; }
  192.  
  193. inline int QRect::height() const
  194. { return  y2 - y1 + 1; }
  195.  
  196. inline QSize QRect::size() const
  197. { return QSize(x2-x1+1, y2-y1+1); }
  198.  
  199.  
  200. #endif // QRECT_H
  201.